<template>
    <div>
        <tsdd v-if="flags" :orderDtail="orderDtail" :Ris="Ris" :Riss="Riss" :marks="marks" :statusFood="statusFood" :riStatus="riStatus" :isShow="isShow"></tsdd>
        <tsddxx v-if="!flags" :orderDtail="orderDtail" :riStatus="riStatus" :Ris="Ris"></tsddxx>
    </div>
</template>
<script>
import tsdd from '../../real-components/ChurchOrderDetail';
import tsddxx from '../../real-components/ChurchOrderDetailOffline';
import { showLoading, hideLoading } from '../../utils/loading.js';
import { orderDetails } from '../../api/wxh/getData';
import { Toast } from '../../utils/toast.js';
import axios from 'axios';
import { mapMutations, mapActions, mapGetters } from "vuex";
export default {
    data() {
        return {
            orderDtail:{},
            Ris:0,//是否全部已取餐状态
            Riss:0,//是否全部缺货
            statusFood:"",//堂食还是打包
            riStatus:0,//是否全部关闭
            isShow:null,
            marks:"",
            flags:true,//是线上还是线下的订单true为线上false为线下
        }
    },
    components: {
        tsdd: tsdd,
        tsddxx: tsddxx
    },
    methods: {
        //判断是否全部已取餐2
        async allGetFoodsly(list){
            // console.log(list,"///////////////////**123")
            // this.Ris = 0;
            await list && list.forEach(elements => {
                let item = elements.orderGoodsList;
                item.forEach(element =>{
                    if( element.eatingStatus != 2 ){
                        this.Ris = 2;
                        hideLoading();
                        return
                        // console.log(this.Ris,"sanfjnaskfnkasnf-2内循环2------")
                    }
                })
            });
            hideLoading();
            // return this.Ris;
        },
        //判断是否全部缺货
        async allGetFoodslys(list){
            // console.log(list,"///////////////////**123")
            // this.Ris = 0;
            await list && list.forEach(elements => {
                let item = elements.orderGoodsList;
                item.forEach(element =>{
                    if( element.eatingStatus != 3 ){
                        this.Riss = 3;
                        // hideLoading();
                        return
                    }
                })
            });
            // hideLoading();
            // return this.Ris;
        },
        // 判断是否全部已关闭
        async allGetFoods(list){
            // console.log(list,"///////////////////**123129")
            // showLoading();
            await list && list.forEach(element => {
                if( element.status != 2){
                    this.riStatus = 1;
                    hideLoading();
                    return
                }
               
            });
            // hideLoading();
            // console.log(this.riStatus,"this.riStatus-----1111111")
        },
        //判断打包还是堂食
        async TangshiOrDabao(list){
            if(list.orderDetailDTOList[0].deliveryType == 'DDST'){
                this.statusFood = '(堂食)';
            }else{
                this.statusFood = '(打包)';
            }
        //    list.orderDetailDTOList[0].deliveryType == 'DDST'?'(堂食)':'(打包)'
        },
         // 查全部的售后信息
        async getAllAfterInfor(value){
            // console.log("查全部的售后信息556677-----",)
            let sessionId =  window.localStorage.sessionId;
            let orderNo = value.orderNo;
            let data ={
                orderNo:orderNo,
                serviceStatus:12
            } 
            let config = {
                url:window.api.service_host+"/afterSales/selectAfterSalesList/",
                method: 'GET',
                // params:JSON.stringify(data),
                params:data,
                headers: {'sessionId': sessionId},
            };
            showLoading();
            await axios(config).then((res) => {
                console.log("查全部的售后信息zhouxin",res)
                try {
                    if(res.data.returnCode === 1){
                        hideLoading();
                        if(res.data.data.length){
                            this.isShow= true;
                            
                        }else{
                            this.isShow= false;
                            
                        }
                        
                    }
                } catch (error) {
                    this.isShow= false;
                    hideLoading();
                }
            })

        },
        
    },
    async created() {
        const id = this.$route.query.shopId || this.$route.query.id;
        // this.flags = this.$route.query.flags;
        showLoading();
        let res = await orderDetails(id);
        let working = '';
        if(res.returnCode === 0) {
            Toast({
                message: res.msg || '数据加载异常！',
                duration: 1000,
                type: 'fail'
            })
            hideLoading();
            // this.$router.push({path: 'login',query:{page:"churchOrderDetail"}})
            this.$router.push({path: 'profile',})
            return
        }
        if(res.returnCode === 1) {
            if(!res.data[0]) {
                Toast({
                    message: res.msg || '无数据！',
                    duration: 1000,
                    type: 'success'
                })
                hideLoading();
                return
            }
            hideLoading();
        }
        this.orderDtail = res.data[0];
        this.$store.dispatch('hzh/PutChildOrderList',this.orderDtail.orderDetailDTOList[0])
        this.allGetFoodsly(res.data[0].paraishOrderGoods);
        this.allGetFoodslys(res.data[0].paraishOrderGoods);
        this.TangshiOrDabao(res.data[0]);
        this.allGetFoods(res.data[0].orderDetailDTOList);
        this.getAllAfterInfor(res.data[0].orderDetailDTOList[0]);
        this.marks = "real";
        console.log(this.orderDtail,"周欣",this.flags)
        if(this.orderDtail.orderDetailDTOList[0].orderType === 3){
            this.flags = true;
        }else if(this.orderDtail.orderDetailDTOList[0].orderType === 4){
            this.flags = false;
        }
        // console.log("周欣bodeng",this.flags)
    },
    mounted(){
        document.querySelector(".home-container").style.transform = "none"
    },
    beforeDestroy() {
        document.querySelector(".home-container").style.transform = "translateX(0px)"
    }
    
}
</script>
<style>
/* .home-container{
    transform: none !important;
    display:inline !important;
} */
</style>
